﻿@model MvcCmsProjectTracker.ViewModels.TicketAttachmentsViewModel
<div id="attachments">
    @if (Model.TicketAttachments.Count() > 0)
    { 
        <table>
            <tr>
                <th>
                    File Name
                </th>
                <th>
                    Uploaded by
                </th>
                <th>
                </th>
            </tr>
            @foreach (var attachment in Model.TicketAttachments)
            { 
                <tr>
                    <td>
                        @Html.ActionLink(attachment.FileName, "GetAttachment", new { id = attachment.AttachmentID })
                    </td>
                    <td>
                        @attachment.UserName
                    </td>
                    <td>
                        @Ajax.ActionLink("Delete", "DeleteAttachment", new { id = attachment.AttachmentID }, new AjaxOptions { HttpMethod="POST", UpdateTargetId = "attachments", OnFailure = "handleFailure", Confirm = "Are you sure you want to delete this attachment?" })
                    </td>
                </tr>
            }
        </table>
    }
    <br />
    @using (Html.BeginForm("AddAttachment", "Ticket", new { id = Model.TicketID }, FormMethod.Post, new { enctype = "multipart/form-data" }))
    { 
        <label for="file">
            Filename:</label>
        <input type="file" name="file" id="file" />
        <input type="submit" name="submit" value="Submit" />
    }
    @Html.Partial("ControlsProjectTracker/Message", Model)
</div>
